-
Notifications
You must be signed in to change notification settings - Fork 21
Add checkpoint primitives #81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| function getCheckpointHash(AccessLogs.Context memory a) | ||
| internal | ||
| pure | ||
| returns (bytes32) | ||
| { | ||
| return a.readLeaf( | ||
| Memory.strideFromLeafAddress( | ||
| EmulatorConstants.checkpointAddress.toPhysicalAddress() | ||
| ) | ||
| ); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this function is returning the hash of the checkpoint hash. Can you verify?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If so, the procedure should be something like:
- call
readLeaf, store result atL; - consume another bytes32, which will be the "alleged" checkpoint hash itself. Store result in
V; - check that the keccak of
VmatchesL; - return
V.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, I totally missed that.
| function setCheckpointHash( | ||
| AccessLogs.Context memory a, | ||
| bytes32 checkPointHash | ||
| ) internal pure { | ||
| a.writeLeaf( | ||
| Memory.strideFromLeafAddress( | ||
| EmulatorConstants.checkpointAddress.toPhysicalAddress() | ||
| ), | ||
| checkPointHash | ||
| ); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Likewise, I think this is writing the hash of the checkpoint hash. Can you verify?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If so, this function should keccak the checkpointHash before writing it.
|
|
||
| uint32 constant IFLAGS_Y_SHIFT = 1; | ||
| uint64 constant LOG2_CYCLES_TO_RESET = 10; | ||
| uint64 constant checkpointAddress = 0x7ffff000; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should use screaming snake case for constants, as the other constants!
src/AdvanceStatus.sol
Outdated
| } | ||
|
|
||
| library AdvanceStatus { | ||
| // START OF AUTO-GENERATED CODE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this autogenerated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not but I supposed it'll be sometimes in the future. Would you like it to be removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think if it's not auto generated, we should remove it.
src/AdvanceStatus.sol
Outdated
| uint64 tohost = | ||
| EmulatorCompat.readWord(a, EmulatorConstants.HTIF_TOHOST_ADDRESS); | ||
| uint16 reason = uint16((tohost >> 16) & ((1 << 16) - 1)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add comments about the endianness, and layout of the tohost register:
typedef struct cmt_io_yield {
uint8_t dev;
uint8_t cmd;
uint16_t reason;
uint32_t data;
} cmt_io_yield_t;
src/AdvanceStatus.sol
Outdated
| enum Status { | ||
| NOT_YIELDED, | ||
| ACCEPTED, | ||
| REJECTED, | ||
| EXCEPTION | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should move this type inside library AdvanceStatus so that it becomes "scoped" to that library.
|
Just checked the new commits, looks great to me. I've added an additional style comment. I'd love for @mpernambuco to take a look as well. Note for reviewers, extracting the yield |
d0f127f to
31de9b1
Compare
src/EmulatorCompat.sol
Outdated
| ) | ||
| ); | ||
| assert(keccak256(abi.encodePacked(checkpointHash)) == hashOfCheckpointHash); | ||
| assert( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I missed this: I think this is a require and not an assert.
31de9b1 to
2753737
Compare
2753737 to
96a22c9
Compare
289984a to
e8050dd
Compare
MANUAL_REASONAdvanceStatus.solCheckpointgetter/setter